package cn.m3a1.service.admin;

import cn.m3a1.bean.*;
import cn.m3a1.dao.CurseMapper;
import cn.m3a1.dao.TclassMapper;
import cn.m3a1.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wyj
 * @date 2019/7/6
 * @time 下午3:30
 */
@Service
public class AdminCourseService {
    @Autowired
    CurseMapper curseMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    TclassMapper tclassMapper;

    /**
     * 获取所有的课程
     *
     * @return
     */
    public List<Curse> getCourceAll() {
        List<Curse> curses = curseMapper.selectAll();
        return curses;
    }

    /**
     * 获取所有的老师
     *
     * @return
     */
    public List<User> getAllTeacher() {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andTypeEqualTo(50);
        List<User> users = userMapper.selectByExample(userExample);
        return users;
    }

    /**
     * 获取所有的班级
     *
     * @return
     */
    public List<Tclass> getAllTclass() {
        TclassExample tclassExample = new TclassExample();
        List<Tclass> tclasses = tclassMapper.selectByExample(tclassExample);
        return tclasses;
    }

    /**
     * 新增课程信息
     */
    public Boolean saveCurse(Curse curse) {

        int i = curseMapper.insertSelective(curse);
        return i == 1;
    }

    /**
     * 更新课程表
     *
     * @param curse
     * @return true表示更新成功
     */
    public Boolean upCurse(Curse curse) {
        CurseExample curseExample = new CurseExample();
        CurseExample.Criteria criteria = curseExample.createCriteria();
        criteria.andIdEqualTo(curse.getId());
        int i = curseMapper.updateByExampleSelective(curse, curseExample);
        return i == 1;
    }

    /**
     * 删除课程信息
     * @return
     */
    public Boolean delCurse(int id) {
        CurseExample curseExample = new CurseExample();
        CurseExample.Criteria criteria = curseExample.createCriteria();
        criteria.andIdEqualTo(id);
        int i = curseMapper.deleteByExample(curseExample);
        return i == 1;
    }

    /**
     * 通过id查询课程信息
     * @param id
     * @return
     */
    public  List<Curse> getCurse(int id){
        CurseExample curseExample=new CurseExample();
        CurseExample.Criteria criteria = curseExample.createCriteria();
        criteria.andIdEqualTo(id);
        List<Curse> curses = curseMapper.selectByExample(curseExample);
        return curses;
    }
}
